package com.monitor.app_monitor.service.quartz.listenner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.monitor.app_monitor.entity.CellectInfo;
import com.monitor.app_monitor.entity.TableList;
import com.monitor.app_monitor.mapper.CellectInfoMapper;
import com.monitor.app_monitor.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;

@Component
@Slf4j
@Order(value = 1)
public class ScheduleJobInitListener implements CommandLineRunner{

    @Autowired
    TaskService scheduleJobService;

//    @Resource
//    @Qualifier("RgEmsMap")
//    private Map<String, AtomicInteger> RgEmsMap;

    @Resource
    @Qualifier("dataAnalysisThreadPool")
    private ThreadPoolExecutor threadPoolExecutor;

    @Resource
    @Qualifier("spcThreadPool")
    private ThreadPoolExecutor spcThreadPool;

    @Override
    public void run(String... arg0) throws Exception {
        try {
            log.info("初始化----------------------------------》");
            scheduleJobService.initSchedule(); //初始化定时任务列表

        } catch (Exception e) {
            e.printStackTrace();
        }

//
//        2
//        getActiveCount   56
//        getQueue56
//        getTaskCount   9234
//                -------------------------
//                getActiveCount   56
//        getQueue6830
//        getTaskCount   11446

        while (true) {
            log.info("==执行脚本线程池队列，正在执行的任务数量：{}，队列数量：{}，队列任务总量：{}==",
                    threadPoolExecutor.getActiveCount()
                    ,threadPoolExecutor.getQueue().size()
                    ,threadPoolExecutor.getTaskCount()
            );
            log.info("-------------------------");
            log.info("==执行文件查询线程池队列，正在执行的任务数量：{}，队列数量：{}，队列任务总量：{}==",
                    spcThreadPool.getActiveCount()
                    ,spcThreadPool.getQueue().size()
                    ,spcThreadPool.getTaskCount()
            );

            Thread.sleep(60000);
        }
    }

}